#include"comm.hpp"


int main()
{
    key_t k = getkey();

    //printf("0x%x\n",k);

    int shmid = getshm(k); 

    //printf("%d\n",shmid);

    char* start = (char*)attchshm(shmid);

    printf("attch success, address start: %p\n",start);

    const char* message = "hello server, 我是另一个进程，正在和你通信";
    pid_t id = getpid();
    int cnt = 1;
    char buffer[1024];
    while(true)
    {
        sleep(1);
        //pid  count  message
        //snprintf(buffer,sizeof(buffer),"%s[pid:%d][消息编号:%d]",message,id,cnt++);
        //memcpy(start,buffer,strlen(buffer)+1);
        snprintf(start,MAX_SIZE,"%s[pid:%d][消息编号:%d]",message,id,cnt++);
    }

    detachshm(start);

    return 0;
}